/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-06-03 11:24:17
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-06-03 11:24:39
 * @FilePath: \project\record-work-time\uniCloud-aliyun\cloudfunctions\JWT\jwt-provider.js
 * @Description: 
 */
const jsonwebtoken = require('jsonwebtoken');
const SECRET_KEY = 'your-256-bit-secret'; // 应使用复杂且安全的密钥
 
// 生成JWT
exports.createToken = function(payload) {
  return jsonwebtoken.sign(payload, SECRET_KEY, { expiresIn: '1h' });
};
 
// 验证JWT
exports.verifyToken = function(token) {
  return new Promise((resolve, reject) => {
    jsonwebtoken.verify(token, SECRET_KEY, (err, decoded) => {
      if (err) {
        reject(err);
      } else {
        resolve(decoded);
      }
    });
  });
};